package com.lswms.modules.lswms.dao.base;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.lswms.common.dao.BaseDao;
import com.lswms.modules.lswms.entity.base.PutawaystrategydetailEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 上架策略明细
 *
 * @author DX sunlightcs@gmail.com
 * @since 1.0.0 2021-06-21
 */
@Mapper
public interface PutawaystrategydetailDao extends BaseDao<PutawaystrategydetailEntity> {

	@Select("select isnull( max(linenum),0) "
			+ "		from lswms_putawaystrategydetail "
			+ "		<where>"
			+ "			strategykey = #{strategykey} "
			+ "		</where>")
	Integer getPutawaystrategydetailMaxLine(@Param("strategykey") String strategykey);

	
	@Select( "select lswms_putawaystrategydetail.*  , a.listname strategycodestr  , b.zonename fromzonecodestr , c.zonename tozonecodestr,d.listname loctypestr,\r\n"
			+ "		e.listname loccategorystr,f.listname locstatusstr,g.name skusortstr,h.listname rowcollevorderstr,i.listname roworderstr,j.listname columnorderstr,k.listname levelorderstr\r\n"
			+ "from lswms_putawaystrategydetail left join lswms_codelist  a on lswms_putawaystrategydetail.strategycode = a.list and a.code ='putawaycode'\r\n"
			+ "	left join lswms_zone b  on lswms_putawaystrategydetail.fromzonecode = b.zonecode \r\n"
			+ "	left join lswms_zone c on lswms_putawaystrategydetail.tozonecode = c.zonecode\r\n"
			+ "	left join lswms_codelist d on lswms_putawaystrategydetail.loc_type = d.list and d.code ='loc_type'\r\n"
			+ "	left join lswms_codelist e on lswms_putawaystrategydetail.loc_category = d.list and e.code ='loc_category'\r\n"
			+ "	left join lswms_codelist f on lswms_putawaystrategydetail.loc_status = f.list and f.code ='loc_status'\r\n"
			+ "	left join lswms_skucategory g on lswms_putawaystrategydetail.skusort   = g.categorykey \r\n"
			+ "	left join lswms_codelist h on lswms_putawaystrategydetail.rowcollevorder = h.list and h.code ='xyzorder'\r\n"
			+ "	left join lswms_codelist i on lswms_putawaystrategydetail.roworder = i.list and i.code ='biggerorsmaller'\r\n"
			+ "	left join lswms_codelist j on lswms_putawaystrategydetail.columnorder = j.list and j.code ='biggerorsmaller'\r\n"
			+ "	left join lswms_codelist k on lswms_putawaystrategydetail.levelorder = k.list and k.code ='biggerorsmaller' ${ew.customSqlSegment}  " )
	IPage<PutawaystrategydetailEntity> selectPageBySql(IPage<PutawaystrategydetailEntity> page,
			@Param(Constants.WRAPPER)QueryWrapper<PutawaystrategydetailEntity> wrapper);
	
}